<?php
namespace tp5_lib\user_access\controller;

use tp5_lib\common\controller\BaseController;
use tp5_lib\access\logic\RoleLogic;
use tp5_lib\access\logic\Access;
use tp5_lib\user\model\UserModel;
use think\facade\Session;

class IndexController extends BaseController
{
    public function index()
    {
        $user=$this->checkLogin();
        $this->assign("user",$user);
        $role=RoleLogic::instance();
        $roles=$role->getRoleNames();
        $this->assign("roles",$roles);
        $privilege = $role->privilege()->stringify();
        $this->assign("privilege",$privilege);
        return $this->fetch();
    }
    public function refresh()
    {
        $user=$this->checkLogin();
        $user_model=new UserModel();
        $user=$user_model->db()->where("id",$user["id"])->find();
        Session::set("user",$user);
        Access::onUserLogin($user);
        $this->redirect("index");
    }
}
